/**
 * @description 用户信息数据持久化
 */
import { defineStore } from 'pinia'
import { wxLogin, getUserInfo, getVolunteerInfo } from '@/api/user.js'
//创建小仓库
export const useUserStore = defineStore('userStore', {
    state: () => ({
        openId: '', // 默认选中的索引
        token: '',
        permissions: [],
        userInfo: {},
        volunteerInfo: {},
    }),
    actions: {
        // appLogin() {
        //     uni.login({
        //         provider: "weixin",
        //         success: (res) => {
        //             // 登录到服务器
        //             wxLogin({
        //                 tempCode: res.code
        //             }).then(
        //                 async (result) => {
        //                     this.openId = result.data.openid
        //                     console.log("获取到openId" + result.data.openid)
        //                     // 获取token的值
        //                     if (result.data.token != '' && result.data.token != null) {
        //                         this.token = result.data.token
        //                         const { permissions, user } = await getUserInfo()
        //                         const { data } = await getVolunteerInfo(result.data.openid)
        //                         this.permissions = permissions
        //                         this.userInfo = user
        //                         this.volunteerInfo = data
        //                     }

        //                 })

        //         },
        //         fail: (err) => {

        //         }
        //     })
        // }
    },
    persist: {
        enabled: true,
    },
})
